package com.aqie.demo.npe;

import java.io.*;

/**
 * @author: aqie
 * @create: 2020-12-26 20:57
 **/
public class TryWithResources {
    public static void main(String[] args) throws IOException, MyException {
        newTryWithResources();
    }

    private static String newTryWithResources() throws IOException, MyException {
        // 1. 单个资源的使用与关闭
        /*try (BufferedReader br = new BufferedReader(new FileReader(""))) {
            return br.readLine();
        }*/

        try (AutoClose autoClose = new AutoClose()) {
            autoClose.work();
        }

        // 2. 多个资源的使用与关闭
        try (FileInputStream in = new FileInputStream("");
             FileOutputStream out = new FileOutputStream("")
        ) {
            byte[] buffer = new byte[100];
            int n = 0;
            while ((n = in.read(buffer)) != -1) {
                out.write(buffer, 0, n);
            }
        }
        return null;
    }
}
